From 972900768d9a460648234d95da811092d5857dca Mon Sep 17 00:00:00 2001 From: "iap10@labyrinth.cl.cam.ac.uk" Date: Sat, 31 Jul 2004 22:17:00 +0000 Subject: [PATCH] bitkeeper revision 1.1108.45.1 (410c1a5ciBWG2JsmEjIJbaQp8U-jtg) Avoid use of /sbin/sfdisk in determining blk dev size. --- .../arch/xen/drivers/blkif/backend/common.h | 3 ++ .../arch/xen/drivers/blkif/backend/vbd.c | 25 +++++++++----- tools/python/xen/xend/XendDomainInfo.py | 34 ++++++++----------- tools/python/xen/xend/server/blkif.py | 6 ++++ 4 files changed, 40 insertions(+), 28 deletions(-) diff --git a/linux-2.4.26-xen-sparse/arch/xen/drivers/blkif/backend/common.h b/linux-2.4.26-xen-sparse/arch/xen/drivers/blkif/backend/common.h index a9f2b87844..c1842033ab 100644 --- a/linux-2.4.26-xen-sparse/arch/xen/drivers/blkif/backend/common.h +++ b/linux-2.4.26-xen-sparse/arch/xen/drivers/blkif/backend/common.h @@ -26,6 +26,9 @@ #define DPRINTK(_f, _a...) ((void)0) #endif +#define PRINTK(_f, _a...) printk(KERN_ALERT "(file=%s, line=%d) " _f, \ + __FILE__ , __LINE__ , ## _a ) + typedef struct blkif_st { /* Unique identifier for this interface. */ domid_t domid; diff --git a/linux-2.4.26-xen-sparse/arch/xen/drivers/blkif/backend/vbd.c b/linux-2.4.26-xen-sparse/arch/xen/drivers/blkif/backend/vbd.c index 8e5d568960..bbb094a4d4 100644 --- a/linux-2.4.26-xen-sparse/arch/xen/drivers/blkif/backend/vbd.c +++ b/linux-2.4.26-xen-sparse/arch/xen/drivers/blkif/backend/vbd.c @@ -18,7 +18,7 @@ void vbd_create(blkif_be_vbd_create_t *create) blkif = blkif_find_by_handle(create->domid, create->blkif_handle); if ( unlikely(blkif == NULL) ) { - DPRINTK("vbd_create attempted for non-existent blkif (%u,%u)\n", + PRINTK("vbd_create attempted for non-existent blkif (%u,%u)\n", create->domid, create->blkif_handle); create->status = BLKIF_BE_STATUS_INTERFACE_NOT_FOUND; return; @@ -41,7 +41,7 @@ void vbd_create(blkif_be_vbd_create_t *create) } else { - DPRINTK("vbd_create attempted for already existing vbd\n"); + PRINTK("vbd_create attempted for already existing vbd\n"); create->status = BLKIF_BE_STATUS_VBD_EXISTS; goto out; } @@ -49,7 +49,7 @@ void vbd_create(blkif_be_vbd_create_t *create) if ( unlikely((vbd = kmalloc(sizeof(vbd_t), GFP_KERNEL)) == NULL) ) { - DPRINTK("vbd_create: out of memory\n"); + PRINTK("vbd_create: out of memory\n"); create->status = BLKIF_BE_STATUS_OUT_OF_MEMORY; goto out; } @@ -85,7 +85,7 @@ void vbd_grow(blkif_be_vbd_grow_t *grow) blkif = blkif_find_by_handle(grow->domid, grow->blkif_handle); if ( unlikely(blkif == NULL) ) { - DPRINTK("vbd_grow attempted for non-existent blkif (%u,%u)\n", + PRINTK("vbd_grow attempted for non-existent blkif (%u,%u)\n", grow->domid, grow->blkif_handle); grow->status = BLKIF_BE_STATUS_INTERFACE_NOT_FOUND; return; @@ -107,7 +107,7 @@ void vbd_grow(blkif_be_vbd_grow_t *grow) if ( unlikely(vbd == NULL) || unlikely(vbd->vdevice != vdevice) ) { - DPRINTK("vbd_grow: attempted to append extent to non-existent VBD.\n"); + PRINTK("vbd_grow: attempted to append extent to non-existent VBD.\n"); grow->status = BLKIF_BE_STATUS_VBD_NOT_FOUND; goto out; } @@ -115,7 +115,7 @@ void vbd_grow(blkif_be_vbd_grow_t *grow) if ( unlikely((x = kmalloc(sizeof(blkif_extent_le_t), GFP_KERNEL)) == NULL) ) { - DPRINTK("vbd_grow: out of memory\n"); + PRINTK("vbd_grow: out of memory\n"); grow->status = BLKIF_BE_STATUS_OUT_OF_MEMORY; goto out; } @@ -127,7 +127,7 @@ void vbd_grow(blkif_be_vbd_grow_t *grow) if( !blk_size[MAJOR(x->extent.device)] ) { - DPRINTK("vbd_grow: device %08x doesn't exist.\n", x->extent.device); + PRINTK("vbd_grow: device %08x doesn't exist.\n", x->extent.device); grow->status = BLKIF_BE_STATUS_EXTENT_NOT_FOUND; goto out; } @@ -135,9 +135,16 @@ void vbd_grow(blkif_be_vbd_grow_t *grow) /* convert blocks (1KB) to sectors */ sz = blk_size[MAJOR(x->extent.device)][MINOR(x->extent.device)] * 2; + if ( sz == 0 ) + { + PRINTK("vbd_grow: device %08x zero size!\n", x->extent.device); + grow->status = BLKIF_BE_STATUS_EXTENT_NOT_FOUND; + goto out; + } + if ( x->extent.sector_start > 0 ) { - DPRINTK("vbd_grow: device %08x start not zero!\n", x->extent.device); + PRINTK("vbd_grow: device %08x start not zero!\n", x->extent.device); grow->status = BLKIF_BE_STATUS_EXTENT_NOT_FOUND; goto out; } @@ -237,7 +244,7 @@ void vbd_destroy(blkif_be_vbd_destroy_t *destroy) blkif = blkif_find_by_handle(destroy->domid, destroy->blkif_handle); if ( unlikely(blkif == NULL) ) { - DPRINTK("vbd_destroy attempted for non-existent blkif (%u,%u)\n", + PRINTK("vbd_destroy attempted for non-existent blkif (%u,%u)\n", destroy->domid, destroy->blkif_handle); destroy->status = BLKIF_BE_STATUS_INTERFACE_NOT_FOUND; return; diff --git a/tools/python/xen/xend/XendDomainInfo.py b/tools/python/xen/xend/XendDomainInfo.py index e7128c06c0..45da2c250f 100644 --- a/tools/python/xen/xend/XendDomainInfo.py +++ b/tools/python/xen/xend/XendDomainInfo.py @@ -83,9 +83,18 @@ def blkdev_name_to_number(name): 'hda') and return the device number used by the OS. """ if not re.match( '^/dev/', name ): - name = '/dev/' + name + n = '/dev/' + name - return os.stat(name).st_rdev + try: + return os.stat(n).st_rdev + except: + pass + + # see if this is a hex device number + if re.match( '^(0x)?[0-9a-fA-F]+$', name ): + return string.atoi(name,16) + + return None def lookup_raw_partn(name): """Take the given block-device name (e.g., '/dev/sda1', 'hda') @@ -97,27 +106,14 @@ def lookup_raw_partn(name): type: 'Disk' or identifying name for partition type """ - p = name - - if not re.match( '^/dev/', name ): - p = '/dev/' + name - - fd = os.popen( '/sbin/sfdisk -s ' + p + ' 2>/dev/null' ) - line = _readline(fd) - if line: - return [ { 'device' : blkdev_name_to_number(p), + n = blkdev_name_to_number(name) + if n: + return [ { 'device' : n, 'start_sector' : long(0), 'nr_sectors' : long(1L<<63), 'type' : 'Disk' } ] else: - # see if this is a hex device number - if re.match( '^(0x)?[0-9a-fA-F]+$', name ): - return [ { 'device' : string.atoi(name,16), - 'start_sector' : long(0), - 'nr_sectors' : long(1L<<63), - 'type' : 'Disk' } ] - - return None + return None def lookup_disk_uname(uname): """Lookup a list of segments for a physical device. diff --git a/tools/python/xen/xend/server/blkif.py b/tools/python/xen/xend/server/blkif.py index 5c62a81e0e..a51754bad3 100755 --- a/tools/python/xen/xend/server/blkif.py +++ b/tools/python/xen/xend/server/blkif.py @@ -194,6 +194,12 @@ class BlkifControllerFactory(controller.ControllerFactory): """ val = unpackMsg('blkif_be_vbd_grow_t', msg) # Check status? + status = val['status'] + if status != BLKIF_BE_STATUS_OKAY: + log.debug("Error: Adding extent to vbd failed! (device %x)", + val['extent.device']) + # what to do here to abort???? + if self.attached: if d: d.callback(dev) -- 2.30.2